package com.oops.support;

import com.oops.model.Position;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.time.format.DateTimeFormatter;
import java.util.Map;

@Mapper
public interface PositionMapper {
    PositionMapper INSTANCE=Mappers.getMapper(PositionMapper.class);
    DateTimeFormatter DATE_TIME_FORMATTER=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Mappings({
            @Mapping(expression = "java( (String)map.get(\"id\"))", target = "id"),
            @Mapping(expression = "java( (String)map.get(\"companyName\"))", target = "companyName"),
            @Mapping(expression = "java( (String)map.get(\"positionName\"))", target = "positionName"),
            @Mapping(expression = "java( (String)map.get(\"positionAdvantage\"))", target = "positionAdvantage"),
            @Mapping(expression = "java( (String)map.get(\"salary\"))", target = "salary"),
            @Mapping(expression = "java( java.lang.Float.valueOf((String)map.get(\"salaryMin\")))", target = "salaryMin"),
            @Mapping(expression = "java( java.lang.Float.valueOf((String)map.get(\"salaryMax\")))", target = "salaryMax"),
            @Mapping(expression = "java( (String)map.get(\"education\"))", target = "education"),
            @Mapping(expression = "java( (String)map.get(\"workYear\"))", target = "workYear"),
            @Mapping(expression = "java( (String)map.get(\"publishTime\"))", target = "publishTime"),
            @Mapping(expression = "java( (String)map.get(\"city\"))", target = "city"),
            @Mapping(expression = "java( (String)map.get(\"workAddress\"))", target = "workAddress"),
            @Mapping(expression = "java( java.time.LocalDateTime.parse((String)map.get(\"createTime\"),DATE_TIME_FORMATTER))", target = "createTime"),
            @Mapping(expression = "java( (String)map.get(\"jobNature\"))", target = "jobNature")
    })
    Position map2Position(Map<String,Object> map);
}
